package com.neusoft.ysu.elm02.service.impl;

import com.neusoft.ysu.elm02.entity.CommonResult;
import com.neusoft.ysu.elm02.entity.Dept;
import com.neusoft.ysu.elm02.mapper.DeptMapper;
import com.neusoft.ysu.elm02.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 作者：赵子鉴
 * @since 2023-08-18
 */
@Service
public class DeptServiceImpl implements IDeptService {
    @Autowired
    private DeptMapper mapper;

    @Override
    public CommonResult insert(Dept dept) {
        int i=mapper.insert(dept);
        return new CommonResult<>(dept.getDeptno());//insert返回主键列生成的值
    }

    @Override
    public CommonResult deleteById(int id) {
        return new CommonResult<>(mapper.deleteById(id));
    }

    @Override
    public CommonResult update(Dept dept) {
        return new CommonResult<>(mapper.updateById(dept));
    }

    @Override
    public CommonResult selectAll() {
        return new CommonResult<>(mapper.selectList(null));
    }

    @Override
    public CommonResult selectById(int id) {
        return new CommonResult<>(mapper.selectById(id));
    }

    @Override
    public CommonResult findDnameList(String dname) {
        dname="*".equals(dname)?"":dname;
        List<String> list = mapper.findDnameList(dname);
        return new CommonResult<>(list);
    }
}
